<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加页面</title>
</head>
<body>
<form class="layui-form" lay-filter="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
				<div class="layui-form-item">
    				<label class="layui-form-label" title="试卷名称">试卷名称</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="name" id="name" placeholder="请输入试卷名称" class="layui-input" lay-verify="">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="分类">分类</label>
    				<div class="layui-input-block">
            			<div class="xmSelect"
                            data-name="category_id"
                            data-sourceType="route"
                            data-source="/admin.category/index"
                            data-sourceTree="false"
                            data-paging="true"
                            data-radio="true"
                            data-valueField="id"
							data-textField="name"
							data-placeholder="请选择分类"
							data-direction="down"
                            ></div>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="课程">课程</label>
    				<div class="layui-input-block">
            			<div class="xmSelect"
                            data-name="course_id"
                            data-sourceType="route"
                            data-source="/admin.course/index"
                            data-sourceTree="false"
                            data-paging="true"
                            data-radio="true"
                            data-valueField="id"
							data-textField="name"
							data-placeholder="请选择课程"
							data-direction="down"
                            ></div>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="描述">描述</label>
    				<div class="layui-input-block">
            			<textarea name="description" id="description" placeholder="请输入描述" class="layui-textarea" lay-verify=""></textarea>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="总分">总分</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="total_score" id="total_score" placeholder="请输入总分" value="0" class="layui-input" lay-verify="number">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="状态">状态</label>
    				<div class="layui-input-block">
            			<!-- 隐藏域设置开关未选中时需要传递的参数值 -->
                        <input type="hidden" name="status" id="status-0" value="0" />
                        <input type="checkbox" name="status" id="status-1" lay-skin="switch" lay-text="发布|待审核" value="发布"  />
    				</div>
				</div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="add">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'],function(){
        layui.form.on('submit(add)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            try{
                data = facade.setEditorField(data);
            }catch (e) {
                facade.error(e);
                return false;
            }
            facade.ajax({
                route:'/admin.exam.papers/add',
                data : data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reloadData("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>